﻿namespace Sidvall.IdentityManager.Security.Entities
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
    public sealed partial class AspNetUserLogins : global::Sidvall.Data.ServiceDataRowBase, global::Sidvall.IdentityManager.Data.IAspNetUserLogins
    {
        #region Public Members

        #region LoginProvider

        private string _LoginProvider;
        partial void OnBeforeLoginProviderPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterLoginProviderPropertyChanged();
        public string LoginProvider
        { 
            get
            {
                return _LoginProvider;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _LoginProvider = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _LoginProvider);
                    OnBeforeLoginProviderPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("LoginProvider", eventData.Value, true, true);
                        OnAfterLoginProviderPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region ProviderKey

        private string _ProviderKey;
        partial void OnBeforeProviderKeyPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterProviderKeyPropertyChanged();
        public string ProviderKey
        { 
            get
            {
                return _ProviderKey;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _ProviderKey = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _ProviderKey);
                    OnBeforeProviderKeyPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("ProviderKey", eventData.Value, true, true);
                        OnAfterProviderKeyPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region UserId

        private string _UserId;
        partial void OnBeforeUserIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterUserIdPropertyChanged();
        public string UserId
        { 
            get
            {
                return _UserId;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _UserId = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _UserId);
                    OnBeforeUserIdPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("UserId", eventData.Value, true, true);
                        OnAfterUserIdPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region DataRowContextStorageKey

        protected override string DataRowContextStorageKey
        {
            get
            {
                return global::Sidvall.IdentityManager.Security.SystemContext.Current.EntityFacade.AspNetUserLoginsManager.GetKey(this);
            }
        }

        #endregion
        #region DataRowStateIsDirty

        protected override bool DataRowStateIsDirty
        {
            get
            {
                return global::Sidvall.IdentityManager.Security.SystemContext.Current.EntityFacade.AspNetUserLoginsManager.DataRowStateIsDirty(this);
            }
        }

        #endregion
        
        public AspNetUsers AspNetUser { get; set; }
        #region LoadAspNetUserAsync

        public async System.Threading.Tasks.Task<AspNetUsers> LoadAspNetUserAsync()
        {
            return await LoadAspNetUserAsync(false, true, null, null, null).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<AspNetUsers> LoadAspNetUserAsync(bool refresh, bool raisePropertyChanged, global::Sidvall.Data.FetchCriteria<global::Sidvall.IdentityManager.Data.Fields.AspNetUsersField, global::Sidvall.IdentityManager.Data.Relations.AspNetUsersRelation> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            await global::Sidvall.IdentityManager.Security.SystemContext.Current.DataPortal.AspNetUserLoginsManager.LoadAspNetUserAsync(this, refresh, raisePropertyChanged, criteria, strategyContext, objectParameters).ConfigureAwait(false);

            return this.AspNetUser;
        }
        public AspNetUsers LoadAspNetUser(AspNetUsers item)
        {
            LoadInstanceField("AspNetUser", item, true, false);
            return item;
        }

        #endregion
        #region LoadInstanceField

        public void LoadInstanceField(string fieldName, object value, bool cascade, bool updateState)
        {
            global::Sidvall.IdentityManager.Security.SystemContext.Current.EntityFacade.AspNetUserLoginsManager.LoadInstanceField(this, fieldName, value, cascade, false, updateState);
        }

        #endregion
        #region Copy

        public AspNetUserLogins Copy()
        {
            return global::Sidvall.IdentityManager.Security.SystemContext.Current.EntityFacade.AspNetUserLoginsManager.Copy(this);
        }
        public AspNetUserLogins Copy(Sidvall.Data.CopySettings settings)
        {
            return global::Sidvall.IdentityManager.Security.SystemContext.Current.EntityFacade.AspNetUserLoginsManager.Copy(this, settings);
        }

        #endregion
        #region Import

        public void Import(global::Sidvall.IdentityManager.Data.IAspNetUserLogins item)
        {
            global::Sidvall.IdentityManager.Security.SystemContext.Current.EntityFacade.AspNetUserLoginsManager.Import(this, item);
        }
        public void Import(global::Sidvall.IdentityManager.Data.IAspNetUserLogins item, Sidvall.Data.CopySettings settings)
        {
            global::Sidvall.IdentityManager.Security.SystemContext.Current.EntityFacade.AspNetUserLoginsManager.Import(this, item, settings);
        }

        #endregion
        #region SaveItemAsync

        public async System.Threading.Tasks.Task<AspNetUserLogins> SaveItemAsync()
        {
            return await global::Sidvall.IdentityManager.Security.SystemContext.Current.DataPortal.AspNetUserLoginsManager.SaveItemAsync(this).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<AspNetUserLogins> SaveItemAsync(Sidvall.Data.SaveMode mode)
        {
            return await global::Sidvall.IdentityManager.Security.SystemContext.Current.DataPortal.AspNetUserLoginsManager.SaveItemAsync(this, mode).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<AspNetUserLogins> SaveItemAsync(Sidvall.Data.SaveSettings settings)
        {
            return await global::Sidvall.IdentityManager.Security.SystemContext.Current.DataPortal.AspNetUserLoginsManager.SaveItemAsync(this, settings).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<AspNetUserLogins> SaveItemAsync(Sidvall.Data.SaveSettings settings, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            return await global::Sidvall.IdentityManager.Security.SystemContext.Current.DataPortal.AspNetUserLoginsManager.SaveItemAsync(this, settings, strategyContext, objectParameters).ConfigureAwait(false);
        }

        #endregion
        #region ValidateAsync

        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync()
        {
            return await global::Sidvall.IdentityManager.Security.SystemContext.Current.EntityFacade.AspNetUserLoginsManager.ValidateAsync(this).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync(Sidvall.Data.ValidationSettings settings)
        {
            return await global::Sidvall.IdentityManager.Security.SystemContext.Current.EntityFacade.AspNetUserLoginsManager.ValidateAsync(this, settings).ConfigureAwait(false);
        }

        #endregion
        #region Initialize

        public void Initialize()
        {
            global::Sidvall.IdentityManager.Security.SystemContext.Current.EntityFacade.AspNetUserLoginsManager.Initialize(this);
        }
        public void Initialize(Sidvall.Data.InitializeSettings settings)
        {
            global::Sidvall.IdentityManager.Security.SystemContext.Current.EntityFacade.AspNetUserLoginsManager.Initialize(this, settings);
        }

        #endregion

        #region IAspNetUserLogins Members

        string global::Sidvall.IdentityManager.Data.IAspNetUserLogins.LoginProvider
        {
            get
            {
                return this._LoginProvider;
            }
            set
            {
                this._LoginProvider = value;
            }
        }
        string global::Sidvall.IdentityManager.Data.IAspNetUserLogins.ProviderKey
        {
            get
            {
                return this._ProviderKey;
            }
            set
            {
                this._ProviderKey = value;
            }
        }
        string global::Sidvall.IdentityManager.Data.IAspNetUserLogins.UserId
        {
            get
            {
                return this._UserId;
            }
            set
            {
                this._UserId = value;
            }
        }
        global::Sidvall.IdentityManager.Data.IAspNetUsers global::Sidvall.IdentityManager.Data.IAspNetUserLogins.AspNetUser
        {
            get
            {
                return this.AspNetUser;
            }
            set
            {
                this.AspNetUser = (AspNetUsers)value;
            }
        }

        #endregion

        #endregion
        #region Constructors

        public AspNetUserLogins()
        {
        }
        public AspNetUserLogins(bool initializeDefaultValues)
            : this(initializeDefaultValues, null, Sidvall.Business.BusinessEvents.None)
        {
        }
        public AspNetUserLogins(bool initializeDefaultValues, Sidvall.Data.DataRowState? dataRowState, Sidvall.Business.BusinessEvents enabledBusinessEvents)
            : base(dataRowState, enabledBusinessEvents)
        {
            if (initializeDefaultValues)
                global::Sidvall.IdentityManager.Security.SystemContext.Current.EntityFacade.AspNetUserLoginsManager.Initialize(this);
        }

        #endregion
    }
}